package com.dz.goods.controller;

import com.dz.common.base.BaseApiService;
import com.dz.common.base.BasePageResultsVO;
import com.dz.common.base.ResponseBase;
import com.dz.goods.domain.entity.Brand;
import com.dz.goods.domain.vo.BrandParamsVO;
import com.dz.goods.domain.vo.BrandResultsVO;
import com.dz.goods.service.BrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/goods/brand")
@Api(tags = "品牌管理")
public class BrandController extends BaseApiService {

    @Autowired
    private BrandService brandService;

    /***
     * 查询全部数据
     * @return
     */
    @GetMapping
    @ApiOperation(value = "获取所有品牌")
    public ResponseBase findAll() throws Exception {
        List<Brand> brandList = brandService.findAll();
        return setResultSuccess(brandList) ;
    }
    @GetMapping("/get_brand_list")
    @ApiOperation(value = "条件查询品牌")
    public ResponseBase getBrandList(BrandParamsVO vo) throws Exception {
        BasePageResultsVO<BrandResultsVO> brandList = brandService.getBrandList(vo);
        return setResultSuccess(brandList) ;
    }
    @PostMapping("/add")
    @ApiOperation(value = "添加品牌")
    public ResponseBase add(@RequestBody Brand brand) throws Exception {
        Brand add = brandService.add(brand);
        return setResultSuccess(add) ;
    }
    @PostMapping("/edit")
    @ApiOperation(value = "更新品牌")
    public ResponseBase edit(@RequestBody Brand brand) throws Exception {
        Brand edit = brandService.edit(brand);
        return setResultSuccess(edit) ;
    }
    @GetMapping("/get_by_id")
    @ApiOperation(value = "根据id查询品牌")
    public ResponseBase getById(Long brandId) throws Exception {
        Brand brand = brandService.findById(brandId);
        return setResultSuccess(brand) ;
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除品牌")
    public ResponseBase delete(Long brandId) throws Exception {
        brandService.delete(brandId);
        return setResultSuccess();
    }
    @GetMapping("/get_by_category_id")
    @ApiOperation(value = "根据分类id查询品牌")
    public ResponseBase findBrandByCategory(Long categoryId) throws Exception {
        List<BrandResultsVO> brandResultsVOList = brandService.findByCategory(categoryId);
        return setResultSuccess(brandResultsVOList) ;
    }
}